﻿using IntelligentDataCollection.BUS;
using IntelligentDataCollection.Models;
using IntelligentDataCollection.Tool;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentDataCollection.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ParameterController : ControllerBase
    {
        public ParameterController()
        {
        }

        [HttpPost]
        [Route("QueryDevice")]
        public ResponseMessage QueryDevice()
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                ParameterBUS parameterBUS = new ParameterBUS();
                message.data = parameterBUS.QueryAllDevice();
                message.errcode = 0;
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "获取设备信息异常";
                LogHelper.Log(ex.ToString());
            }
            return message;
        }

        [HttpPost]
        [Route("UpdateDevice")]
        public ResponseMessage UpdateDevice(List<DeviceInfo> infos)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                ParameterBUS parameterBUS = new ParameterBUS();
                message = parameterBUS.UpdateDevice(infos);
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "获取设备信息异常";
                LogHelper.Log(ex.ToString());
            }
            return message;
        }

        [HttpPost]
        [Route("QueryStorage")]
        public ResponseMessage QueryStorage()
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                ParameterBUS parameterBUS = new ParameterBUS();
                message.data = parameterBUS.QueryStorage();
                message.errcode = 0;
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "获取设备信息异常";
                LogHelper.Log(ex.ToString());
            }
            return message;
        }


        [HttpPost]
        [Route("UpdateStorage")]
        public ResponseMessage UpdateStorage(StorageInfo storageInfo)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                ParameterBUS parameterBUS = new ParameterBUS();
                message = parameterBUS.UpdateStorage(storageInfo);
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "获取设备信息异常";
                LogHelper.Log(ex.ToString());
            }
            return message;
        }
    }
}
